function class(classname, super)
    local cls = {__cname = classname}

    if super then
        local superType = type(super)
        assert(superType == "nil" or superType == "table" or superType == "function",
                string.format("class() - create class \"%s\" with invalid super class type \"%s\"",
                        classname, superType))

        if superType == "function" then
            assert(cls.__create == nil,
                    string.format("class() - create class \"%s\" with more than one creating function",
                            classname));
            -- if super is function, set it to __create
            cls.__create = super
        elseif superType == "table" then
            if super[".isclass"] then
                -- super is native class
                assert(cls.__create == nil,
                        string.format("class() - create class \"%s\" with more than one creating function or native class",
                                classname));
                cls.__create = function() return super:create() end
            else
                -- super is pure lua class
                cls.super = super
            end
        else
            error(string.format("class() - create class \"%s\" with invalid super type",
                    classname), 0)
        end
    end

    cls.__index = cls
    setmetatable(cls, {__index = cls.super})

    if not cls.ctor then
        -- add default constructor
        cls.ctor = function() end
    end

    if not cls.__gc then
        cls.__gc = function()
            --print('GC!!!!!', cls.__cname)
        end
    end

    cls.new = function(...)
        local instance
        if cls.__create then
            instance = cls.__create(...)
        else
            instance = {}
        end

        setmetatable(instance, cls)
        instance.class = cls

        local construct
        construct = function(c, ins,...)
            if c.super then
                construct(c.super, ins, ...)
            end

            if c.ctor then
                c.ctor(ins,...)
            end
        end
        construct(cls, instance, ...)
        return instance
    end
    cls.create = function(_, ...)
        return cls.new(...)
    end

    return cls
end
